<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head th:replace="/common/include :: header(~{::title}, ~{::link}, ~{::style})">
	<title>系统管理-参数管理</title>
</head>
<body class="gray-bg">
    <div class="container-div">
		<div class="row">
			<th:block th:include="/common/breadcrumb :: breadcrumb"/>
			<div class="col-sm-12 search-collapse">
				<form id="search-form">
					<div class="select-list row">
						<div class="col-sm-3 col-xs-6">
							<div class="control-label">参数名称：</div>
							<div><input class="form-control" type="text" name="Q_configName_S_LK"/></div>
						</div>
						<div class="col-sm-3 col-xs-6">
							<div class="control-label">系统内置：</div>
							<div>
								<select class="form-control selectpicker" name="Q_configType_S_EQ" th:with="type=${@dict.getDataGroup('sys_yes_no_char')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
								</select>
							</div>
						</div>
						<div class="control-label right-btn">
							<a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search('bootstrap-table', 'search-form')"><i class="fa fa-search"></i>&nbsp;搜索</a>
							<a class="btn btn-default btn-rounded btn-sm" onclick="$.form.reset('search-form')"><i class="fa fa-refresh"></i>&nbsp;重置</a>
						</div>
					</div>
				</form>
			</div>

            <div class="btn-group-sm" id="toolbar" role="group">
		        <a class="btn btn-success" onclick="add()" th:classappend="${@config.hasPermission('tool:config:add')}">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-warning btn-edit disabled" onclick="edit()" th:classappend="${@config.hasPermission('tool:config:edit')}">
		            <i class="fa fa-edit"></i> 修改
		        </a>
				<a class="btn btn-danger btn-del disabled" onclick="del()" th:classappend="${@config.hasPermission('tool:config:delete')}">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-default" onclick="exportConfig()" th:classappend="${@config.hasPermission('tool:config:view')}">
					<i class="fa fa-export"></i> 导出
				</a>
	        </div>

			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
	    </div>
	</div>

	<div th:replace="/common/include :: footer"></div>

	<script th:inline="javascript">
		var addFlag = [[${@config.hasPermission('tool:config:add')}]];
		var editFlag = [[${@config.hasPermission('tool:config:edit')}]];
		var removeFlag = [[${@config.hasPermission('tool:config:delete')}]];
		var status_data_list = [[${@dict.getDataGroup('sys_yes_no_char')}]];
		var prefix = ctx + 'api/system/config';

		$(function() {
            var options = {
                code: "configId",
                url: prefix + "/table",
                sortName: "configId",
                sortOrder: "asc",
                search: false,
                pagination: true,
                columns: [{
					field: 'rowState',
                    checkbox: true
                },
                    {
                        field: 'configName',
                        title: '参数名称',
                        sortable: true
                    },
                    {
                        field: 'configKey',
                        title: '参数键名'
                    },
                    {
                        field: 'configValue',
                        title: '参数键值',
						formatter: function(value, row, index) {
							return $.common.render.ellipsis(value, 70);
						}
                    },
                    {
                        field: 'configType',
                        title: '系统内置',
                        align: 'center',
                        formatter: function(value, row, index) {
                            return $.common.dictLabel(status_data_list, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        width: '80px',
                        formatter: function(value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn-xs btn-outline btn-success ' + editFlag + '" href="#" onclick="edit(\'' + row.configId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn-xs btn-outline btn-danger ' + removeFlag + '" href="#" onclick="del(\'' + row.configId + '\')"><i class="fa fa-remove"></i>删除</a> ');
							return $.common.dropdown(actions.join(''));
                        }
                    }]
            };
            $.table.init('bootstrap-table', options);
		});

        function add() {
            var title = '新增参数';
            var url = ctx + 'api/tool/config/edit';

            $.operate.edit({
                title: title,
                content: url,
				width: '650',
				height: '500',
                shadeClose: true,
                _index: window.name,
                _callback: 'refresh'
            });
        }

		function edit(id) {
            var title = '编辑参数';
            var url = ctx + 'api/tool/config/edit';
            if (!id) {
                url = url + '?id={id}';
                $.operate.editSelect({
                    type: 'table',
                    title: title,
                    content: url,
					width: '650',
					height: '500',
                    shadeClose: true,
                    _index: window.name,
                    _callback: 'refresh'
                }, false);
                return;
            }

            url = url + '?id=' +id;
            $.operate.edit({
                title: title,
                content: url,
				width: '650',
				height: '500',
                shadeClose: true,
                _index: window.name,
                _callback: 'refresh'
            });
		}

		function del(id) {
            var url = prefix + '/delete';
            if (!id) {
                $.operate.removeSelect('bootstrap-table', url, '确定删除选中的数据吗？', 'table', 'refresh');
                return;
            }
            $.operate.remove(url, id, null, 'refresh');
		}

        function exportConfig() {
            var url = prefix + '/export';
            $.table.exportExcel(url, 'search-form');
        }

		function refresh() {
		    $.table.refresh();
		}

	</script>
</body>
</html>